﻿@model MvcWeb.ViewModels.User.UserModel
@using System.Configuration          
@{
    ViewBag.Title = "用户编辑";
}
<style type="text/css">
    label { margin-right: 10px; }
</style>
<div style="padding: 10px;">
    <div style="padding-bottom: 5px;">
        <input type="button" onclick="history.go(-1)" value="返回用户列表" class="btn_green" />
    </div>
    <div style="height: 30px; line-height: 30px; background-color: lightyellow; padding: 0px 10px; border: 1px dashed red; margin-bottom: 10px;">
        提示：添加人员后初始密码为@(ConfigurationManager.AppSettings["DefaultPwd"])，请登录后自行修改。
    </div>
    @using (Html.BeginForm())
    {
        <div style="line-height: 30px; font-weight: bold; color: Red;">@Model.Error</div>
        <table class="tb">
            <tr>
                <td>@Html.LabelFor(m => m.UserName)</td>
                <td>
                    @if (ViewContext.RouteData.Values["id"] == null)
                    {
                        @Html.TextBoxFor(m => m.UserName)
                        @Html.ValidationMessageFor(m => m.UserName)
                    }
                    else
                    {
                        @Html.DisplayFor(m => m.UserName)
                    }
                </td>
            </tr>
            <tr>
                <td>@Html.LabelFor(m => m.RealName)</td>
                <td>
                    @Html.TextBoxFor(m => m.RealName)
                    @Html.ValidationMessageFor(m => m.RealName)
                </td>
            </tr>
            <tr>
                <td>@Html.LabelFor(m => m.DeptId)</td>
                <td>
                    @Html.HiddenFor(m => m.DeptId)
                    @Html.TextBoxFor(m => m.DeptName)
                </td>
            </tr>
            <tr>
                <td>所属角色</td>
                <td>
                    @foreach (var m in Model.AllRoleList)
                    {
                        <label>
                            <input type="checkbox" name="roleName" value="@m" @(Model.RoleList != null && Model.RoleList.Contains(m) ? @"checked=""checked""" : "") />@m</label>
                    }
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="submit" value="保存" class="btn_green" />
                    <input type="reset" value="重置" class="btn_orange" />
                </td>
            </tr>
        </table>
    }
</div>
<script type="text/javascript">
    $(function () {
        var tree = $("#DeptName").ligerComboBox({
            width: 180,
            selectBoxWidth: 200,
            selectBoxHeight: 200,
            tree: { url: '/dept/root?t=' + Math.random(), checkbox: false },
            onSelected: function (newvalue) {
                $("#DeptId").val(newvalue);
            }
        });

        var deptID = $("#DeptId").val();
        if (deptID != '') {
            tree.selectValue(deptID);
        }
    });
</script>
